﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CPPEI.Coolzon.UI.DataPartLib.XProperty.Editors
{
    public class GridColumnModel : INotifyPropertyChanged
    {
        public static explicit operator GridColumnModel(GridColumn gridColumn)
        {
            GridColumnModel ret = new GridColumnModel();
            ret.Name = gridColumn.Name;
            ret.Caption = gridColumn.Caption;
            ret.DataItemId = gridColumn.DataItemId;
            ret.ImagePrefixs = gridColumn.ImagePrefixs;
            ret.ImageSuffixs = gridColumn.ImageSuffixs;
            ret.HAlignment = gridColumn.HAlignment;
            ret.VAlignment = gridColumn.VAlignment;
            ret.Width = gridColumn.Width;
            ret.TextFormat = gridColumn.TextFormat;
            ret.ValueType = gridColumn.ValueType;
            ret.Padding = gridColumn.Padding;
            ret.Columns = new ObservableCollection<GridColumnModel>();
            if(gridColumn.Columns != null)
            {
                foreach (var item in gridColumn.Columns)
                {
                    GridColumnModel target = (GridColumnModel)item;
                    target.Parent = ret;
                    ret.Columns.Add(target);
                }
            }
            return ret;
        }

        public static explicit operator GridColumn(GridColumnModel gridColumnModel)
        {
            GridColumn ret = new GridColumn();
            ret.Name = gridColumnModel.Name;
            ret.Caption = gridColumnModel.Caption;
            ret.DataItemId = gridColumnModel.DataItemId;
            ret.ImagePrefixs = gridColumnModel.ImagePrefixs;
            ret.ImageSuffixs = gridColumnModel.ImageSuffixs;
            ret.HAlignment = gridColumnModel.HAlignment;
            ret.VAlignment = gridColumnModel.VAlignment;
            ret.Width = gridColumnModel.Width;
            ret.TextFormat = gridColumnModel.TextFormat;
            ret.ValueType = gridColumnModel.ValueType;
            ret.Padding = gridColumnModel.Padding;
            ret.Columns = new List<GridColumn>();
            if(gridColumnModel.Columns != null)
            {
                foreach (var item in gridColumnModel.Columns)
                {
                    ret.Columns.Add((GridColumn)item);
                }
            }
            return ret;
        }
        public GridColumnModel Parent { get; set; }

        private string _Name;
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
                NotifyPropertyChanged();
            }
        }
        public string Caption { get; set; }
        public string DataItemId { get; set; }

        public List<GridColumnConditionImage> ImagePrefixs { get; set; }

        public List<GridColumnConditionImage> ImageSuffixs { get; set; }

        public string HAlignment { get; set; }
        public string VAlignment { get; set; }

        public double? Width { get; set; }

        public string TextFormat { get; set; }
        /// <summary>
        /// value的类型string,double,int,float,datetime等
        /// double: {0:d2}%,{0:d2}
        /// </summary>
        public string ValueType { get; set; }

        /// <summary>
        /// 列的内部间距
        /// </summary>
        public Thickness Padding { get; set; }

        public ObservableCollection<GridColumnModel> Columns { get; set; }

        private bool _IsSelected;
        public bool IsSelected
        {
            get
            {
                return _IsSelected;
            }
            set
            {
                _IsSelected = value;
                NotifyPropertyChanged();
            }
        }

        private bool _IsExpanded;
        public bool IsExpanded
        {
            get { return _IsExpanded; }
            set
            {
                _IsExpanded = value;
                NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = "")
        {
            if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
